package cmd

import (
	"strings"
)

var (
	//系统配置

	StopSelinux = "setenforce 0 && sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"
	StopSwap    = "swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab"

	FreshSysCtl = "sysctl --system"
	ClusterInit = "mkdir -p $HOME/.kube && cp -i /etc/kubernetes/admin.conf $HOME/.kube/config && chown $(id -u):$(id -g) $HOME/.kube/config"
)

func CheckHostIsVm() string {
	cmd := "dmidecode -s system-product-name | grep -i virtual"
	return cmd
}
func InstallPkgString(pkgName string) string {
	cmd := "rpm -ivh " + pkgName
	return cmd
}

func PkgInfoString(pkgName string) string {
	cmd := "rpm -qpi " + pkgName
	return cmd
}
func RemovePkgString(pkgName string) string {
	cmd := "rpm -e " + pkgName
	return cmd
}

func MkDirString(dirName string) string {
	cmd := "mkdir -p " + dirName
	return cmd
}

func TouchFileOverrideString(fileName, content string) string {
	cmd := "cat << EOF > " + fileName + "\n" + content + "\nEOF"
	return cmd
}

func GetDNSServerIp() string {
	cmd := "kubectl get svc -n kube-system | grep kube-dns | awk '{ print $3 }'"
	return cmd
}

func TouchFileAppendString(fileName, content string) string {
	cmd := "cat << EOF >> " + fileName + "\n" + content + "\nEOF"
	return cmd
}

func SetHostNameString(hostName string) string {
	cmd := "hostnamectl set-hostname " + hostName
	return cmd
}

func SetHostsString(IP, hostName string) string {
	data := IP + " " + hostName
	cmd := "cat << EOF >> " + "/etc/hosts" + "\n" + data + "\nEOF"
	return cmd
}

func SetFstab(IP, path string) string {
	localPath := "   /mnt/data     nfs    defaults  0 0"
	data := IP + ":" + path + localPath
	cmd := "cat << EOF >> " + "/etc/fstab" + "\n" + data + "\nEOF"
	return cmd
}

func GetHostsInfoString() string {
	cmd := "cat /etc/hosts"
	return cmd

}
func EnableServiceString(service string) string {

	cmd := "systemctl enable " + service
	return cmd
}

func RestartServiceString(service string) string {

	cmd := "systemctl restart " + service
	return cmd
}

func StartServiceString(service string) string {

	cmd := "systemctl start " + service
	return cmd
}
func StopServiceString(service string) string {

	cmd := "systemctl stop " + service
	return cmd
}

func DisableServiceString(service string) string {

	cmd := "systemctl disable " + service
	return cmd
}

func StatusServiceString(service string) string {

	cmd := "systemctl status " + service
	return cmd
}

func SaveDockerImageString(image string) string {
	imageNewName := strings.ReplaceAll(image, "/", "_")
	cmd := "docker save " + image + ">" + imageNewName
	return cmd
}

func LoadDockerImageString(image string) string {
	cmd := "docker load < " + image
	return cmd
}

/*func KubeAdmInitString(opts install.KubeAdmJoinOpts) string {

	return "kubeadm init " + "--kubernetes-version " + opts.KubernetesVersion + " --apiserver-advertise-address " +
		opts.ApiserverAdvertiseAddress + " --image-repository " + opts.ImageRepository + " --service-cidr " +
		opts.ServiceCidr + " --pod-network-cidr " + opts.PodNetworkCidr + " | kubeadm-init.log"
}*/

/*func KubeAdmjoinString(opts install.KubeAdmJoinOpts) string {

	return "kubeadm join " + opts.MasterIP + " --discovery-token-ca-cert-hash " +
		opts.DiscoveryTokenCaCertHash + " --token " + opts.Token
}*/
